package com.wintrue.ffxs.widget.area;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.wintrue.ffxs.R;
import com.wintrue.ffxs.utils.DensityUtil;

public class BottomDialog extends Dialog {
    private AddressSelector selector;
    private Context mContext;
    private String mProvinceNameSelected;
    private String mCityNameSelected;
    private String mAreaNameSelected;
    private String mTownNameSelected;

    public BottomDialog(Context context) {
        super(context, R.style.bottom_dialog);
        this.mContext = context;
    }

    public BottomDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
    }

    public BottomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
    }

    public void init(String type) {
        selector = new AddressSelector(mContext,type,mProvinceNameSelected,mCityNameSelected,mAreaNameSelected,mTownNameSelected);
        setContentView(selector.getView());

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = DensityUtil.dip2px(mContext, 350);
        window.setAttributes(params);

        window.setGravity(Gravity.BOTTOM);
    }

    /**
     * 设置默认选中值，必须在init方法之前
     * @param provinceName
     * @param cityName
     * @param areaName
     * @param townName
     */
    public void setSelectedDafult(String provinceName,String cityName,String areaName,String townName){
        this.mProvinceNameSelected = provinceName;
        this.mCityNameSelected = cityName;
        this.mAreaNameSelected = areaName;
        this.mTownNameSelected = townName;
    }

    public void setOnAddressSelectedListener(OnAddressSelectedListener listener) {
        this.selector.setOnAddressSelectedListener(listener);
    }

    public static BottomDialog show(Context context,String type) {
        return show(context, null);
    }

//    public static BottomDialog show(Context context, OnAddressSelectedListener listener,String type) {
//        BottomDialog dialog = new BottomDialog(context, R.style.bottom_dialog,type);
//        dialog.selector.setOnAddressSelectedListener(listener);
//        dialog.show();
//
//        return dialog;
//    }
}
